<template>
	<view class="container">
		<view class="banner">
			<u-swiper :list="[goods.logo_url]" mode="number" indicator-pos="bottomRight" :autoplay=false height="600"></u-swiper>
		</view>
		<view class="content">
			<!-- 商品服务 -->
			<view class="service">
				<view class="service-item">
					<text class="service-item-name">额度</text>
					<text class="service-item-content">最高可贷{{goods.max_amount}}元</text>
				</view>
				<view class="service-item">
					<text class="service-item-name">期限</text>
					<text class="service-item-content">{{goods.min_term}}-{{goods.max_term}}个月</text>
				</view>
				<view class="service-item">
					<text class="service-item-name">利率</text>
					<text class="service-item-content">年化{{goods.min_annual_rate}}%-{{goods.max_annual_rate}}%</text>
				</view>
			</view>
			<!-- 详细信息 -->
			<view class="detail">
				<view class="detail-title">产品介绍</view>
        <u-parse :html="goods.content"></u-parse>
			</view>
		</view>

		<!-- 底部栏 -->
		<view class="bottombar">
			<view class="bottombar-content">
        <button class="contact" type="default" open-type="contact"></button>
				<view class="bottombar-content-item">
					<image src="/static/icon/kefu2.png"></image>
					<text>客服</text>
				</view>
			</view>
			<view class="bottombar-btn">
				<button @click="openDialog">提交申请</button>
			</view>
		</view>

		<u-popup v-model="applyPopupShow" mode="bottom" border-radius="14" :closeable="true">
			<view class="apply-form-container">
				<u-form :model="applyForm" ref="applyFormRef" label-width="160rpx">
					<u-form-item label="联系人" prop="contact_person" required label-position="top">
						<u-input v-model="applyForm.contact_person" placeholder="请输入联系人" border="none" />
					</u-form-item>
					<u-form-item label="联系方式" prop="contact_phone" required label-position="top">
						<u-input v-model="applyForm.contact_phone" placeholder="请输入联系方式" border="none" />
					</u-form-item>
					<u-form-item label="社保缴纳基数" prop="social_security_base" label-position="top">
						<u-input v-model="applyForm.social_security_base" type="number" placeholder="请输入社保缴纳基数" border="none" />
					</u-form-item>
					<u-form-item label="公积金缴纳基数" prop="housing_fund_base" label-position="top">
						<u-input v-model="applyForm.housing_fund_base" type="number" placeholder="请输入公积金缴纳基数" border="none" />
					</u-form-item>
					<u-form-item label="工资区间" prop="salary_range" label-position="top">
						<u-input
							v-model="applyForm.salary_range"
							placeholder="请选择工资区间"
							border="none"
							readonly
							@click="showSalarySheet = true"
						/>
					</u-form-item>
					<u-action-sheet :list="salaryRangeList" v-model="showSalarySheet" @click="onSalaryRangeSelect"></u-action-sheet>
					<u-form-item label="补充信息" prop="application_data" label-position="top">
						<u-input v-model="applyForm.application_data" type="textarea" placeholder="补充信息（选填）" border="none" />
					</u-form-item>
				</u-form>
				<view class="form-btn">
					<button @click="submitApplication">提交</button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
        isCollect: false,
				popupShow: false,
				banner: [],
				goods: {
          id: 0,
          name: '',
          is_recommend: 0,
          logo_url: '',
          category_id: 0,
          max_amount: 0,
          min_annual_rate: 0,
          max_annual_rate: 0,
          min_term: 0,
          max_term: 0,
          description: '',
          content: '',
          status: 1,
          comments: []
				},
        resCount: 0,
				count: 1,
				specsWeight: 1,
        id: 0,
        applyPopupShow: false,
        applyForm: {
          contact_person: '',
          contact_phone: '',
          social_security_base: '',
          housing_fund_base: '',
          salary_range: '',
          application_data: '',
        },
        showSalarySheet: false,
        salaryRangeList: [
          {text: '5000以下'},
          {text: '5000-10000'},
          {text: '10000-20000'},
          {text: '20000以上'}
        ],
			};
		},
    onLoad({ id }) {
      if (id) {
        this.id = id
      }
    },
    onShow() {
      if (this.id) {
        let id = this.id
        this.$api.getProductDetail(id).then(res => {
          this.goods = res
        })
      }
    },
		methods: {
      openDialog() {
        this.applyPopupShow = true
      },
	    submitApplication() {
        if (!this.applyForm.contact_person || !this.applyForm.contact_phone) {
          this.$utils.toastTip('请填写联系人和联系方式');
          return;
        }
        uni.showLoading();
        this.$api.submitApplication({
          user_id: this.$store.state.userInfo.id,
          product_id: this.goods.id,
          ...this.applyForm,
          application_data: this.applyForm.application_data
        }).then(res => {
          uni.hideLoading();
          this.applyPopupShow = false;
          this.$utils.toastTip('申请已提交');
        });
      },
      onSalaryRangeSelect(e) {
        this.applyForm.salary_range = this.salaryRangeList[e].text;
      }
		}
	}
</script>

<style>
	page {
		background: #F8F9FA;
	}
</style>

<style lang="scss" scoped>
	.banner {}

	.content {
		margin: 20rpx;

		.info {
			background: #FFFFFF;
			padding: 20rpx 20rpx 26rpx 20rpx;
			border-radius: 20rpx;

			.goods-price {
				display: flex;
				align-items: center;
				justify-content: space-between;
				color: #F55726;
				font-size: 22rpx;
				border-radius: 20rpx;

				.goods-price-left {
					display: flex;
					align-items: flex-end;

					.goods-price-txt {
						font-size: 42rpx;
						font-weight: 600;

						.goods-unit-txt {
							font-size: 22rpx;
							color: #999999;
							font-weight: normal;
						}
					}

					.old-price {
						color: #CCCCCC;
						text-decoration: line-through;
						margin-left: 8rpx;
					}
				}

				.goods-price-right {
					display: flex;
					align-items: center;

					text {
						border: 1rpx solid #CCCCCC;
						border-radius: 4rpx;
						margin-right: 10rpx;
						color: #CCCCCC;
						padding: 2rpx 4rpx;
					}
				}
			}

			.goods-name {
				font-size: 34rpx;
				font-weight: 600;
				color: #333333;
				margin-top: 10rpx;
			}

			.goods-label {
				margin-top: 20rpx;
				display: flex;
				align-items: center;

				.goods-label-name {
					background: #40AE36;
					border-radius: 6rpx;
					font-size: 22rpx;
					color: #FFFFFF;
					padding: 4rpx 10rpx;
				}

				.goods-label-content {
					font-size: 22rpx;
					color: #666666;
					margin-left: 10rpx;
				}
			}
		}

		.service {
			background: #FFFFFF;
			margin-top: 20rpx;
			padding: 20rpx;
			border-radius: 20rpx;

			.service-item {
				display: flex;
				align-items: center;
				line-height: 52rpx;

				.service-item-name {
					color: #999999;
					font-size: 24rpx;
				}

				.service-item-content {
					color: #333333;
					font-size: 24rpx;
					margin-left: 20rpx;
				}
			}
		}

		.specs {
			border-radius: 20rpx;
			background: #FFFFFF;
			margin-top: 20rpx;
			padding: 24rpx 10rpx 22rpx 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			font-size: 26rpx;

			text:nth-child(1) {
				font-weight: bold;
				color: #333333;
			}

			text:nth-child(2) {
				margin-left: 16rpx;
			}

			image {
				width: 48rpx;
				height: 48rpx;
			}

		}

		.specs-popup {
			background: #FFFFFF;
			padding: 34rpx 56rpx 20rpx 56rpx;

			.specs-popup-title {
				font-size: 32rpx;
				font-weight: 600;
				color: #333333;
				text-align: center;
			}

			.specs-popup-weight {
				margin-top: 50rpx;

				.specs-popup-weight-txt {
					color: #333333;
					font-size: 28rpx;
				}

				.specs-popup-weight-list {
					margin-top: 34rpx;

					text {
						width: 160rpx;
						margin-right: 24rpx;
						color: #333333;
						padding: 10rpx 40rpx;
						border-radius: 16rpx;
						background: #F8F9FA;
					}

					.specs-weight-active {
						color: #40AE36;
					}
				}
			}

			.specs-popup-num {
				margin-top: 50rpx;
				margin-bottom: 100rpx;

				.specs-popup-num-txt {
					color: #333333;
					font-size: 28rpx;
				}

				.specs-popup-num-box {
					margin-top: 34rpx;
				}
			}


			.specs-popup-btn {
				width: 100%;
				padding: 24rpx 0rpx;

				button {
					flex: 1;
					border-radius: 46rpx;
					background: #40AE36;
					color: #FFFFFF;
					font-size: 26rpx;
					padding: 12rpx 0rpx;
				}
			}
		}

		.comment {
			background: #FFFFFF;
			margin-top: 20rpx;
			padding: 10rpx 10rpx 22rpx 20rpx;
			border-radius: 20rpx;

			.comment-top {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 10rpx 0rpx 22rpx 0rpx;
				border-bottom: 1rpx solid #EBEBEB;

				.comment-top-left {

					text:nth-child(1) {
						font-size: 26rpx;
						font-weight: bold;
						color: #333333;
					}

					text:nth-child(2) {
						font-size: 22rpx;
						color: #999999;
						margin-left: 4rpx;
					}
				}

				.comment-top-right {
					display: flex;
					align-items: center;

					text {
						font-size: 24rpx;
					}

					image {
						width: 48rpx;
						height: 48rpx;
					}
				}
			}

			.comment-bottom {
				padding-top: 30rpx;

				.comment-info {
					display: flex;

					.comment-bottom-right {
            flex-grow: 1;
						padding: 0rpx 20rpx;

						.comment-nickname {
							display: flex;
							align-items: center;
							justify-content: space-between;

							text:nth-child(1) {
								font-size: 24rpx;
								font-weight: 600;
								color: #333333;
							}

							text:nth-child(2) {
								font-size: 22rpx;
								color: #999999;
							}
						}

						.comment-content {
							margin-top: 20rpx;
							color: #666666;
							font-size: 24rpx;
              margin-bottom: 12rpx;
						}
            .comment-image {
              display: flex;
              align-items: center;
              flex-wrap: wrap;

              .comment-image-item {
                margin-right: 20rpx;
                margin-top: 20rpx;
              }

              image {
                width: 112rpx;
                height: 112rpx;
              }
            }

					}

				}

				image {
					width: 70rpx;
					height: 70rpx;
					border-radius: 50%;
				}
			}
		}

		.detail {
			background: #FFFFFF;
			margin-top: 20rpx;
			padding: 10rpx 10rpx 120rpx 20rpx;
			border-radius: 20rpx;

			.detail-title {
				color: #333333;
				font-size: 26rpx;
				font-weight: 600;
				padding: 10rpx 20rpx 10rpx 0rpx;
			}

			.detail-table {
				margin-top: 20rpx;
			}
		}
	}

	.bottombar {
		position: fixed;
		bottom: var(--window-bottom, 0);
		width: 100%;
		background: #FFFFFF;
		display: flex;
		align-items: center;

		.bottombar-content {
			display: flex;
			align-items: center;
			padding: 20rpx;
      position: relative;
      .contact{
        position: absolute;
        width: 100%;
        height: 120rpx;
        top:0;
        left:0;
        opacity: 0;
      }

			image {
				width: 36rpx;
				height: 36rpx;
			}

			.bottombar-content-item {
				display: flex;
				flex-direction: column;
				align-items: center;
				margin-right: 60rpx;
				min-width: 60rpx;

				text {
					font-size: 18rpx;
					margin-top: 2rpx;
				}
			}
		}

		.bottombar-btn {
			display: flex;
			align-items: center;
			width: 100%;
			padding-right: 20rpx;

			button {
				flex: 1;
				border-radius: 36rpx;
        background: rgba(255, 195, 0, 1);
				color: #FFFFFF;
				font-size: 26rpx;
			}
		}

	}

	.apply-form-container {
		padding: 32rpx;
		.form-card {
			background: #fff;
			border-radius: 16rpx;
			margin-bottom: 24rpx;
			padding: 24rpx;
			input, textarea {
				width: 100%;
				border: none;
				background: transparent;
				font-size: 30rpx;
				outline: none;
			}
			textarea {
				min-height: 80rpx;
				resize: none;
			}
		}
		.u-input {
			background: #f7f7f7 !important;
			border: none !important;
			border-radius: 8rpx;
		}
		.form-btn {
			margin-top: 24rpx;
			button {
				width: 100%;
				border-radius: 16rpx;
        background: rgba(255, 195, 0, 1);
				color: #fff;
				font-size: 32rpx;
			}
		}
	}
</style>
